package com.njtoyo.netrides.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.taxi.entity.json.PointCustomerSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.geolatte.geom.Point;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * Created by astropete on 2017/8/16.
 */
@Entity
@Table(name = "taxi")
@Accessors(chain = true)
@Data
@EqualsAndHashCode(of = {"id"})
public class Taxi {

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String plateNumber;

    private String serialNumber;

    @JsonIgnore
    private Date createdAt;

    @JsonIgnore
    private Date updatedAt;

    @JsonIgnore
    private Boolean isAvailable;

    @JsonIgnore
    private Integer lastLocateTimestamp;

    @JsonIgnore
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "taxi")
    private Set<Driver> drivers;

    @ManyToOne
    @JoinColumn(name = "company_id")
    @JsonIgnore
    private Company company;

    @JsonIgnore
    private String taxiDetails;

    @Column(columnDefinition = "geometry(Point,4326)")
    @JsonSerialize(using = PointCustomerSerializer.class)
    private Point lastLocate;

}
